﻿package {
	import flash.display.*;
	import flash.net.URLRequest;
	import flash.events.*;
	import flash.media.*;

	//import Main_View;

	/**
	 * @author Administrator
	 */
	public class Main {
		var MainMc : MovieClip;

		public function Main(mc : MovieClip = null) {
			if (Boolean(mc)) {
				this.MainMc = mc;
				//var mv:Main_View = new Main_View(mc,this);
				LoadSwf(mc.loading, "loading.swf");
				LoadSwf(mc.bg, "bg.jpg");
				主菜单_加载SWF();
			}
		}

		/**
		 * 加载Swf
		 */
		public function LoadSwf(mc : MovieClip,Url : String,Fun : Function = null) : void {
			var loader : Loader = new Loader();
			loader.load(new URLRequest(Url));
			if ( Boolean(Fun)) {
				loader.contentLoaderInfo.addEventListener(Event.COMPLETE, Fun);
			}
			trace(mc.numChildren) 
			// 2
			if(Boolean(mc.numChildren)) {
				mc.removeChildAt(0);
				trace("SoundMixer.stopAll();"); 
				SoundMixer.stopAll();
			}
			trace(mc.numChildren) 
			// 2
			
			//
			mc.addChild(loader);
		}

		public function 主菜单_加载SWF(e : Event = null) : void {
			LoadSwf(this.MainMc.view, "main_view.swf", this.主菜单_加载事件);//
		}

		public function 主菜单_加载事件(e : Event) : void {
			var mc : MovieClip = e.target.content;
			mc.跟读训练_按钮.addEventListener(MouseEvent.CLICK, this.跟读训练_加载SWF);
			mc.对话训练_按钮.addEventListener(MouseEvent.CLICK, this.对话训练_加载SWF);
			mc.阅读训练_按钮.addEventListener(MouseEvent.CLICK, this.阅读训练_加载SWF);
			mc.写作训练_按钮.addEventListener(MouseEvent.CLICK, this.写作训练_加载SWF);
			mc.听力训练_按钮.addEventListener(MouseEvent.CLICK, this.听力训练_加载SWF);
			mc.老师讲坐_按钮.addEventListener(MouseEvent.CLICK, this.老师讲坐_加载SWF);
			mc.随堂测试_按钮.addEventListener(MouseEvent.CLICK, this.随堂测试_加载SWF);
			mc.索引_按钮.addEventListener(MouseEvent.CLICK, this.索引_加载SWF);
		}

		public function 跟读训练_加载SWF(e : Event) : void {
			LoadSwf(this.MainMc.view, "跟读训练.swf", this.返回_事件加载);//
		}

		public function 对话训练_加载SWF(e : Event) : void {
			LoadSwf(this.MainMc.view, "对话联系.swf", this.返回_事件加载);//
		}

		public function 阅读训练_加载SWF(e : Event) : void {
			LoadSwf(this.MainMc.view, "阅读训练.swf", this.返回_事件加载);//
		}

		public function 写作训练_加载SWF(e : Event) : void {
			LoadSwf(this.MainMc.view, "写作练习.swf", this.返回_事件加载);//
		}

		public function 听力训练_加载SWF(e : Event) : void {
			LoadSwf(this.MainMc.view, "听力训练.swf", this.返回_事件加载);//
		}

		public function 老师讲坐_加载SWF(e : Event) : void {
			LoadSwf(this.MainMc.view, "老师讲座.swf", this.返回_事件加载);//
		}

		public function 随堂测试_加载SWF(e : Event) : void {
			LoadSwf(this.MainMc.view, "跟读训练.swf", this.返回_事件加载);
		}

		public function 索引_加载SWF(e : Event) : void {
			LoadSwf(this.MainMc.view, "跟读训练.swf", this.返回_事件加载);
		}

		public function 返回_事件加载(e : Event) {
			var mc : MovieClip = e.target.content;
			mc.返回.addEventListener(MouseEvent.CLICK, this.主菜单_加载SWF);
			
		}
	}
}